package net.openvision.music.composition;


public class OctaveValueClass implements ValueClass {

	public class Iterator implements java.util.Iterator<Byte> {
		private byte current;
		private byte max;
		
		public Iterator(byte max) {
			current = (byte)(value-OCTAVE);
			this.max = max;
		}

		@Override
		public boolean hasNext() {
			return current+OCTAVE < max;
		}

		@Override
		public Byte next() {
			current+=OCTAVE;
			return current;
		}

		@Override
		public void remove() {
			throw new UnsupportedOperationException();
		}
	}
	
	public static final byte OCTAVE = 12;
	protected static final byte MAX = Byte.MAX_VALUE;
	
	private byte value;
	
	public OctaveValueClass(byte value) {
		this.value = (byte)(value%OCTAVE);
	}
	
	@Override
	public boolean contains(byte value) {
		return ((byte)(value%OCTAVE) == this.value);
	}
	
	public byte difference(OctaveValueClass vc) {
		if (value > vc.value)
			return (byte)(value - vc.value);
		else
			return (byte)(vc.value - value);
	}

	@Override
	public java.util.Iterator<Byte> iterator() {
		return new Iterator(MAX);
	}

}
